$(function () {
    var tab_index = getCookie("tab_index");
    if (tab_index != '' && tab_index != null && typeof(tab_index) != 'undefined') {
        tabSwitch(tab_index);
    } else {
        tabSwitch(0);
    }


    $("body").on('click', '.wm-buttons-tab>a', function () {
        $(this).addClass("active").siblings().removeClass("active");
        var index = $(this).data("index");
        SetCookie('tab_index', index);
        tabSwitch(index)
    });

    function tabSwitch(index) {
        $('.wm-buttons-tab>a').removeClass("active");
        $('.wm-buttons-tab>a').each(function () {
            if ($(this).data("index") == index) {
                $(this).addClass("active");
            }
        });

        if (index == 1) {
            $("#status").val(1);
        } else if (index == 2) {
            $("#status").val(2);
        } else {
            $("#status").val('');
        }
        //为了分页加载数据不冲突
        if ($("#task-list").children().length > 0) {
            $(".infinite-scroll-preloader").remove();
            var loading = '<section class="loading-gif__wrap"><div class="row"><aside class="col-auto"><span class="loadingImg"></span></aside><aside class="col-auto"><span class="loading-txt"><big>努力奔跑中...</big><br></span></aside></div></section>';
            $("#task-list").remove();
            $(".media-list").append(loading);
            setTimeout(function () {
                $("#task-list").remove();
                $(".infinite-scroll-preloader").remove();
                $(".loading-gif__wrap").remove();
                $(".media-list").append('<ul id="task-list"></ul>');
                $("#task-list").append(loading);
                loadMyTaskData(1);
            }, 1200);
        } else {
            loadMyTaskData(1);
        }


    }

    function loadMyTaskData(pageNo) {
        var params = {
            "status": $("#status").val()
        };
        params = JSON.stringify(params);
        loadMobilePathData({
            url: baseloaction + '/mobile/uc/operation/ajax/operationIndex',
            contextId: 'task-list',
            pageNo: pageNo,
            pageCall: loadMyTaskData,
            params: params,
            callback: function (pageNo) {
            }
        });
    }


});

function goBack() {
    var noMobile = getCookie("noMobile");
    if (noMobile != null) {
        if (noMobile == "1" ){
            android.goBack();
        }
        if( noMobile == "2") {
            window.webkit.messageHandlers.goBack.postMessage("");
        }
        return true;
    }
    window.location.href = baseloaction + "/mobile/uc/index"
}